//初始化加载一级品类
function goods_listCategory1(classNum, parentId) {
    var user_data = {
        category_level: classNum
    }
    var succCallBack = function(data, status, response) {
        if(data.errorCode == "0") {
            if(data.data == null) {
                $("#classSet1").append('<li class="clearfix pl-10 mb-5">无数据</li>');
                $("#classSet1").append('<li id="firstClassInp1" style="display: none" class="clearfix pl-10 mb-5"><div class="f-l pd-5"><label class="pl-10" id="addLabel1">22</label></div><div class=" f-l class-input"><input type="text" autofocus class="input-text radius f-l firstClassId1" name="" placeholder=""><div class="f-l"><span class="msgError" style="color: red;"></span></div><div class="f-r pt-5"><a href="##" onclick="addClass(1,0,\'.firstClassId1\')" class="ml-10">确认</a><a href="##" onclick="celClassFirstAdd(\'#firstClassInp1\')" class="ml-10">取消</a></div></div></li>')
            } else {
                // 标记修改
                $("#classSet1").append('<li id="firstClassInp1" style="display: none" class="clearfix pl-10 mb-5"><div class="f-l pd-5"><label class="pl-10" id="addLabel1">22</label></div><div class=" f-l class-input"><input type="text" autofocus class="input-text radius f-l firstClassId1" name="" placeholder=""><div class="f-l"><span class="msgError" style="color: red;"></span></div><div class="f-r pt-5"><a href="##" onclick="addClass(1,0,\'.firstClassId1\')" class="ml-10">确认</a><a href="##" onclick="celClassFirstAdd(\'#firstClassInp1\')" class="ml-10">取消</a></div></div></li>')
                for(var i = 0; i < data.data.length; i++) {
                    $("#classSet1").append('<li class="clearfix pl-10 mb-5"><div class="f-l pd-5"><input onclick="goods_listCategory2(2,this.value)" name="classification01" type="checkbox" value="' + data.data[i].category_id + '" class="checkbox" /><label class="pl-10">' + data.data[i].category_code + ' <input title="' + data.data[i].category_name + '" type="text" value="' + data.data[i].category_name + '" disabled style="height: 24px;width: 145px;border: 0px;background: white;margin-top: -4px"></label></div></li>')
                }
            }
        }
    };
    web.doAjax(root.goodsInter.goods_listCategory, 'post', user_data, succCallBack);
}
goods_listCategory1(1);

// 商品分类名称验证
function validClass(e) {
    var value = $(e).val();
    if (value == null || value == "") {
        $.Huimodalalert("不能为空，请输入", 1000);
        return false;
    }
    var reg = /^[a-zA-Z0-9\u4e00-\u9fa5、]{0,15}$/;
    var flag = reg.test(value);
    if (flag == false) {
        $(e).val(value.match(/[a-zA-Z0-9\u4e00-\u9fa5、]{0,15}/));// 去除非法字符
        return false;
    }
    return true;
}

function goods_listCategory2(classNum, parentId,isShowInput) {
    sessionStorage.setItem("parentId2", parentId);
    $("#classDiv2").css({
        display: "none"
    });
    $("#classDiv3").css({
        display: "none"
    });
    $("#classDiv4").css({
        display: "none"
    });
    $("#classDiv2").css({
        display: "block"
    });
    $(".removeEl2").remove();
    var user_data = {
        // category_level: classNum,
        category_id: parentId
    }
    var succCallBack = function(data, status, response) {
        if(data.errorCode == "0") {
            if(data.data == null) {
                $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5">无数据</li>');
                $("#classSet2").append('<li  class="removeEl2 clearfix pl-10 mb-5" id="firstClassInp2" style="display: none"><div class="f-l pd-5"><label class="pl-10" id="addLabel2"></label></div><div class=" f-l class-input"><input type="text" autofocus class="input-text radius f-l firstClassId2" name="" placeholder=""><div class="f-l"><span class="msgError" style="color: red;"></span></div><div class="f-r pt-5"><a href="##" onclick="addClass(2,' + parentId + ',\'.firstClassId2\')" class="ml-10">确认</a><a href="##" onclick="celClassFirstAdd(\'#firstClassInp2\')" class="ml-10">取消</a></div></div></li>')
                if(isShowInput == true){
                    setTimeout(function () {
                        $("#addLabel2").html(JSON.stringify(sessionStorage.getItem("goods_addClass")).code);
                    },200)

                    $("#firstClassInp2").css({
                        display:"block"
                    })
                }
            } else {
                // 标记修改
                $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5" id="firstClassInp2" style="display: none"><div class="f-l pd-5"><label class="pl-10" id="addLabel2"></label></div><div class=" f-l class-input"><input type="text" autofocus class="input-text radius f-l firstClassId2" name="" placeholder=""><div class="f-l"><span class="msgError" style="color: red;"></span></div><div class="f-r pt-5"><a href="##" onclick="addClass(2,' + parentId + ',\'.firstClassId2\')" class="ml-10">确认</a><a href="##" onclick="celClassFirstAdd(\'#firstClassInp2\')" class="ml-10">取消</a></div></div></li>');
                if(isShowInput == true){
                    setTimeout(function () {
                        $("#addLabel2").html(JSON.stringify(sessionStorage.getItem("goods_addClass")).code);
                    },200)

                    $("#firstClassInp2").css({
                        display:"block"
                    })
                }
                for(var i = 0; i < data.data.length; i++) {
                    $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5"><div class="f-l pd-5"><input onclick="goods_listCategory3(3,this.value)" name="classification02" type="checkbox" value="' + data.data[i].category_id + '" class="checkbox" /><label class="pl-10">' + data.data[i].category_code + ' <input title="' + data.data[i].category_name + '" type="text" value="' + data.data[i].category_name + '" disabled style="height: 24px;width: 145px;border: 0px;background: white;margin-top: -4px"></label></div></li>')
                }
            }
        }
    };
    web.doAjax(root.goodsInter.goods_subCategory, 'post', user_data, succCallBack);
}

function goods_listCategory3(classNum, parentId,isShowInput) {
    sessionStorage.setItem("parentId3", parentId);
    $("#classDiv3").css({
        display: "block"
    });
    $(".removeEl3").remove();
    var user_data = {
        category_id: parentId
    }
    var succCallBack = function(data, status, response) {
        if(data.errorCode == "0") {
            if(data.data == null) {
                $("#classSet3").append('<li class="removeEl3 clearfix pl-10 mb-5">无数据</li>');
                $("#classSet3").append('<li  class="removeEl3 clearfix pl-10 mb-5" id="firstClassInp3" style="display: none"><div class="f-l pd-5"><label class="pl-10" id="addLabel3"></label></div><div class=" f-l class-input"><input type="text"  autofocus class="input-text radius f-l firstClassId3" name="" placeholder=""><div class="f-l"><span class="msgError" style="color: red;"></span></div><div class="f-r pt-5"><a href="##" onclick="addClass(3,' + parentId + ',\'.firstClassId3\')" class="ml-10">确认</a><a href="##" onclick="celClassFirstAdd(\'#firstClassInp3\')" class="ml-10">取消</a></div></div></li>');
                if(isShowInput == true){
                    setTimeout(function () {
                        $("#addLabel3").html(JSON.stringify(sessionStorage.getItem("goods_addClass")).code);
                    },200)
                    $("#firstClassInp3").css({
                        display:"block"
                    })
                }
            } else {
                // 获得光标
                $("#classSet3").append('<li  class="removeEl3 clearfix pl-10 mb-5" id="firstClassInp3" style="display: none"><div class="f-l pd-5"><label class="pl-10" id="addLabel3"></label></div><div class=" f-l class-input"><input type="text" autofocus class="input-text radius f-l firstClassId3" name="" placeholder=""><div class="f-l"><span class="msgError" style="color: red;"></span></div><div class="f-r pt-5"><a href="##" onclick="addClass(3,' + parentId + ',\'.firstClassId3\')" class="ml-10">确认</a><a href="##" onclick="celClassFirstAdd(\'#firstClassInp3\')" class="ml-10">取消</a></div></div></li>');
                if(isShowInput == true){
                    setTimeout(function () {
                        $("#addLabel3").html(JSON.stringify(sessionStorage.getItem("goods_addClass")).code);
                    },200);

                    $("#firstClassInp3").css({
                        display:"block"
                    })
                }
                for(var i = 0; i < data.data.length; i++) {
                    $("#classSet3").append('<li class="removeEl3 clearfix pl-10 mb-5"><div class="f-l pd-5"><input onclick="goods_listCategory4(4,this.value)" name="classification03" type="checkbox" value="' + data.data[i].category_id + '" class="checkbox" /><label class="pl-10">' + data.data[i].category_code + ' <input title="' + data.data[i].category_name + '" type="text" value="' + data.data[i].category_name + '" disabled style="height: 24px;width: 145px;border: 0px;background: white;margin-top: -4px"></label></div></li>')
                }
            }
        }
    };
    return web.doAjax(root.goodsInter.goods_subCategory, 'post', user_data, succCallBack);
}

function goods_listCategory4(classNum, parentId) {
    sessionStorage.setItem("parentId4", parentId);
    $("#classDiv4").css({
        display: "block"
    });
    $(".removeEl4").remove();
    var user_data = {
        // category_level: classNum,
        category_id: parentId
    }
    var succCallBack = function(data, status, response) {
        if(data.errorCode == "0") {
            if(data.data == null) {
                $("#classSet4").append('<li class="removeEl4 clearfix pl-10 mb-5">无数据</li>');
                $("#classSet4").append('<li  class="removeEl4 clearfix pl-10 mb-5" id="firstClassInp4" style="display: none"><div class="f-l pd-5"><input name="classification04" type="checkbox" value="" class="checkbox" /><label class="pl-10" id="addLabel4"></label></div><div class=" f-l class-input"><input type="text"  autofocus class="input-text radius f-l firstClassId4" maxlength="15" name="" placeholder=""><div class="f-l pt-5"><a href="##" onclick="addClass(4,' + parentId + ',\'.firstClassId4\')" class="ml-10">确认</a><a href="##" onclick="celClassFirstAdd(\'#firstClassInp4\')" class="ml-10">取消</a></div></div></li>')
            } else {
                $("#classSet4").append('<li  class="removeEl4 clearfix pl-10 mb-5" id="firstClassInp4" style="display: none"><div class="f-l pd-5"><input name="classification04" type="checkbox" value="" class="checkbox" /><label class="pl-10" id="addLabel4"></label></div><div class=" f-l class-input"><input type="text" autofocus  class="input-text radius f-l firstClassId4" maxlength="15" name="" placeholder=""><div class="f-l pt-5"><a href="##" onclick="addClass(4,' + parentId + ',\'.firstClassId4\')" class="ml-10">确认</a><a href="##" onclick="celClassFirstAdd(\'#firstClassInp4\')" class="ml-10">取消</a></div></div></li>')
                for(var i = 0; i < data.data.length; i++) {
                    $("#classSet4").append('<li class="removeEl4 clearfix pl-10 mb-5"><div class="f-l pd-5"><input name="classification04" type="checkbox" value="' + data.data[i].category_id + '" class="checkbox" /><label class="pl-10">' + data.data[i].category_code + ' <input title="' + data.data[i].category_name + '" type="text" value="' + data.data[i].category_name + '" disabled style="height: 24px;width: 145px;border: 0px;background: white;margin-top: -4px"></label></div></li>')
                }
            }
        }
    };
    return web.doAjax(root.goodsInter.goods_subCategory, 'post', user_data, succCallBack);
}